import { getSblxBySbzlx } from '../../../../../mapUtils/SblxUtil';
import { projectLngLatToWebMercator } from '../../../../../mapUtils/CoordinateUtil';
import CONST from '../../../../../constant/Common';
import IpmsPoint from '../IpmsPoint';
import RuleResult from '../vo/RuleResult';

/**
 * 环网柜修改
 * @implements {IpmsPoint}
 */
class PmsHwg extends IpmsPoint {
  constructor(_tool) {
    super(_tool);
    this.defaultSbzlx = 32400000;
    this.defaultDydj = 22;
    this.drawtype = 'pms_hwg';
    this.defaultName = '新增环网柜';
    this.defaultIcon = 'hw_default';
  }

  /**
   * 新增环网柜
   * @override
   * @param {Object} option 默认参数
   * @param {Array} snapList 捕捉图形
   */
  draw(option, snapList) {
    return super.draw(option, snapList);
  }

  /**
   * 编辑环网柜
   * @override
   * @param {Object} option 默认参数
   * @param {Array} snapList 捕捉图形
   */
  edit(option, snapList) {
    return super.edit(option, snapList);
  }

  /**
   * 获取当前绘制设备信息
   * @override
   */
  async getTargetDevice() {
    let coordinates = projectLngLatToWebMercator(this.geometry.coordinates);
    let data = {
      sbmc: this.option.sbmc || this.defaultName,
      dydj: this.defaultDydj,
      cenX: coordinates[0],
      cenY: coordinates[1],
      schema: this.option.schema,
      versionid: this.option.versionid || '',
      ghrw: this.option.ghrw || '',
      ghfa: this.option.ghfa || '',
      ghnf: this.option.ghnf || '',
      ghxm: this.option.ghxm || '',
      ssqy: this.option.ssqy || '',
      city: this.option.city || '',
      fxlx: this.option.fxlx || 2,
      sblx: getSblxBySbzlx(this.defaultSbzlx),
      sbzlx: this.defaultSbzlx,
      shape: this.getGeometryWkt(this.geometry),
      verRule: CONST.verRule
    };
    if (this.type === 'edit') {
      data.oid = this.option.oid;
      data.shapeList = this.getChangedShapeList();
    }
    return data;
  }

  /**
   * 验证点合理性
   * @override
   * @param {Number} index 点下标
   * @param {*} snap 捕捉到的设备
   */
  async _ruleJudgePoint(index, snap) {
    let layer = snap.layer;
    if (layer) {
      // 如果不是空点
      if (layer.properties.sbzlx === CONST.tempPoint) {
        // 先判断是否是虚拟点，判断虚拟点是否和架空线路相连
        // let isTempPointConnJkxl = await this._isTempPointConnJkxl(layer.properties);
        // if (isTempPointConnJkxl) {
        //   return new RuleResult(false, index, "环网柜不能连接架空线路");
        // } else {
        //   return new RuleResult(true, index, "success");
        // }
        return new RuleResult(true, index, 'success');
      }
      return new RuleResult(false, index, '环网柜只可以和线路一端相连');

    }
    // 如果是空点，直接通过
    return new RuleResult(true, index, 'success');

  }
}

export default PmsHwg;
